<script setup lang='ts'>
  import { reactive, ref } from 'vue';
  import { numberApi } from '@/api/controller';
  import { ToastWarning, Toastloading } from '@/utils/public';
  import Pagination from "@/components/Pagination/index.vue";
  import forbidUserForm from '../userList/components/forbidUserForm.vue';
  const forbidUserFormRef = ref()
  const action = reactive({
    total:0,
    list:[] as any[],
  })
  const listQuery = reactive({
    page:1,
    limit:20,
    uuid:'',
  })
  const handleForm = (row:any = {},operate_type=1)=>{
    forbidUserFormRef.value.openDialog({
      operate_type,
      ...row
    })
  }
  const handleSerach = ()=>{
    listQuery.page = 1
    getList()
  }
  const getList = async()=> {
    if(!listQuery.uuid) return ToastWarning('请输入用户UUID')
    const loading = Toastloading()
    const res = await numberApi.accountNumber(listQuery)
    loading.close()
    const { data=[], total=0 } = res?.data?.list || {}
    action.total = total
    action.list = data
  }
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">用户UUID：</div>
          <el-input v-model="listQuery.uuid" placeholder="请输入UUID" />
        </div>
        <div class="labelItem">
          <el-button type="primary" @click="handleSerach">查询</el-button>
        </div>
      </div>
    </div>
    <el-table
      class="xm-TableCenter"
      :data="action.list"
      border>
      <el-table-column width="120" prop="user_id" label="user_id" />
      <el-table-column width="120" prop="uuid" label="UUID" />
      <el-table-column min-width="120" show-overflow-tooltip prop="nickname" label="昵称" />
      <el-table-column width="120" prop="mobile_phone" label="手机号" />
      <el-table-column width="180" prop="idcard_name" label="证件姓名" />
      <el-table-column width="180" prop="idcard_number" label="证件号码" />
      <el-table-column width="120" label="状态">
        <template #default="scoped">
          <span v-if="scoped.row.forbid_status == 1" style="color: blue">正常</span>
          <span v-else-if="scoped.row.forbid_status == 2" style="color: red">已封号</span>
        </template>
      </el-table-column>
      <el-table-column width="120" label="操作" >
        <template #default="scoped">
          <el-button
            v-show="scoped.row.forbid_status == 1"
            type="danger"
            @click="handleForm(scoped.row,1)"
            v-rule="'number_handleforbid'"
          >封号</el-button>
          <el-button
            v-show="scoped.row.forbid_status == 2"
            type="primary"
            @click="handleForm(scoped.row,0)"
            v-rule="'number_deblocking'"
          >解封</el-button>
        </template>
      </el-table-column>
    </el-table>
    <Pagination v-show="action.total > 0" :total="action.total" v-model:page="listQuery.page"
      v-model:limit="listQuery.limit" @pagination="getList" />
    <forbidUserForm ref="forbidUserFormRef" @update-list="getList" />
  </div>
</template>